package reflect;

import reflect.annotations.AutoRunMethod;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

/**
 * 使用反射机制调用Person类中所有被@AutoRunMethod标注的方法
 */
public class Test2 {
    public static void main(String[] args) throws Exception {
        //1
        Class cls = Class.forName("reflect.Person");
        Object obj = cls.newInstance();
        //2
        Method[] methods = cls.getMethods();
        //3
        for(Method method : methods){
            if(method.isAnnotationPresent(AutoRunMethod.class)){
                //4
                method.invoke(obj);
            }
        }
    }
}
